<template>
  <div class="app-page">
    <el-table-form ref="form" :model="query">
      <el-form-item class="merge-item">
        <el-select v-model="csmType" style="width: 170px; margin-right: 2px;">
          <el-option label="报修单号" value="repairCode" />
          <el-option label="客户电话" value="contactPhone" />
          <el-option label="客户编号" value="csmCode" />
          <el-option label="客户名称" value="csmName" />
          <el-option label="处理人" value="userName" />
          <el-option label="登记人" value="answer" />
          <el-option label="报修内容" value="repairContent" />
        </el-select>
        <el-input v-model.trim="csmText" placeholder="请输入" clearable />
      </el-form-item>
      <el-form-item label="责任机构:" prop="orgSNNo">
        <el-tree-select
          v-model="query.orgSNNo"
          clearable
          class="tree-select"
          :popover-width="360"
          :select-params="{
            clearable: true,
            placeholder: '请选择',
            loading: $loadingPlugin.getTreeData,
          }"
          :tree-params="{
            'expand-on-click-node': false,
            'highlight-current': true,
            'filterable': true,
            props: {
              value: 'orgSNNo',
              label: 'orgName',
              disabled: 'disabled',
            },
            data: treeData,
          }"
          @node-click="selectTreeChange"
          @select-clear="closeTree"
        />
      </el-form-item>
      <el-form-item label="处理人:" prop="userId">
        <el-select
          v-model="query.userId"
          :loading="$loadingPlugin.getOwnersList"
          filterable
          clearable
          placeholder="请选择"
        >
          <el-option
            v-for="item in ownersList"
            :key="item.userId"
            :label="item.userName"
            :value="item.userId"
          />
        </el-select>
      </el-form-item>
      <el-form-item :table-form-merge="2" class="merge-item">
        <el-select v-model="dateType" style="width: 170px; margin-right: 2px;">
          <el-option label="登记时间" value="createTime" />
          <el-option label="完成时间" value="signDt" />
          <!-- <el-option label="回访时间" value="callTime" /> -->
          <el-option label="审核时间" value="auditTime" />
          <el-option label="派单时间" value="transferTime" />
          <!-- <el-option label="报修处理时间" value="callTime" />
          <el-option label="驳回时间" value="callTime" /> -->
        </el-select>
        <el-date-picker
          v-model="date"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          format="yyyy-MM-dd HH:mm"
          unlink-panels
          :default-time="['00:00:00', '23:59:59']"
          :clearable="false"
        />
      </el-form-item>
      <el-form-item label="状态:" prop="rstatus">
        <el-select v-model="query.rstatus" filterable clearable placeholder="请选择">
          <el-option
            v-for="item in repairStatusMap"
            :key="item.value"
            :label="item.desc"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="回访结果:" prop="visitStatus">
        <el-select v-model="query.callResult" filterable clearable placeholder="请选择">
          <el-option
            v-for="item in visitStatusMap"
            :key="item.value"
            :label="item.desc"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="回访调查:" prop="callCheck">
        <el-select v-model="query.callCheck" filterable clearable placeholder="请选择">
          <el-option
            v-for="item in callCheckMap"
            :key="item.backVisitDesc"
            :label="item.backVisitDesc"
            :value="item.backVisitDesc"
          />
        </el-select>
      </el-form-item> -->
      <el-form-item label="来源:" prop="fromPlat">
        <el-select v-model="query.fromPlat" filterable placeholder="请选择" clearable>
          <el-option
            v-for="item in fromPlatMap"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="报修内容:" prop="repairContent">
        <el-select v-model="query.repairContent" filterable placeholder="请选择" clearable>
          <el-option
            v-for="item in repairContentMap"
            :key="item.keyName"
            :label="item.keyName"
            :value="item.keyName"
          />
        </el-select>
      </el-form-item>
      <template v-slot:btns>
        <el-button
          v-permission="1"
          type="primary"
          icon="el-icon-search"
          @click="search"
        >查询</el-button>
      </template>
    </el-table-form>
    <div style="margin-bottom: 10px;" class="btn-group">
      <div>
        <el-button
          v-permission="2"
          type="primary"
          icon="el-icon-download"
          @click="exportFile"
        >导出</el-button>
      </div>
    </div>
    <lb-table
      ref="lbTable"
      v-el-height-adaptive-table="{ bottomOffset: 10 }"
      border
      highlight-current-row
      element-loading-text="加载中"
      :column="column"
      :data="tableData.data"
      pagination
      :immediate-fetch="false"
      :total="tableData.total"
      custom-column
      @fetch="fetchData"
    />
    <detail
      ref="detail"
      @openPressOrder="openPressOrder"
      @openTransferOrder="openTransferOrder"
      @dealConfirm="dealConfirm"
      @openReturnVisit="openReturnVisit"
      @openBackOrder="openBackOrder"
      @openRemark="openRemark"
      @audit="audit"
      @dealReject="dealReject"
    />
    <csm-detail ref="csmDetail" :tree-data="treeData" :calc-type-list="calcTypeList" :paymen-fil-list="paymenFilList" />
    <deal-confirm ref="dealConfirm" />
    <transfer-order ref="transferOrder" />
    <press-order ref="pressOrder" />
    <remark-order ref="remarkOrder" />
    <back-order ref="backOrder" />
    <return-visit ref="returnVisit" :visit-status-map="visitStatusMap" />
    <rejectReason ref="rejectReason" />
    <securityOrderInfo
      ref="securityOrderInfo"
      :tree-data="treeData"
    />
  </div>
</template>

<script>
  import {
    queryRepairList,
    queryOwnerList,
    queryRepairOrderMap,
    queryExportRepairOrderList,
    queryRepairOrderDetail,
    queryMap,
    repairAudit,
    repairCommonkeys
  } from '@/api'
  import { formatColumnMap, parseTime } from '@/utils'
  import getTreeData from '@/utils/jsonTree'
  import { mergeAsyncFunc } from '@/utils/mergeAsyncFunc'
  import { mapGetters } from 'vuex'
  import Detail from './components/Detail'
  import DealConfirm from './components/DealConfirm'
  import TransferOrder from './components/TransferOrder'
  import PressOrder from './components/pressRepair'
  import RemarkOrder from './components/Remark'
  import BackOrder from './components/BackOrder'
  import ReturnVisit from './components/ReturnVisit'
  import CsmDetail from '../../components/CsmDetailModal/index.vue'
  import moment from 'dayjs'
  import RejectReason from './components/rejectReason.vue'

  const colorObj = {
    1: 'color:#ff0000;',
    2: 'color:#cc33ff;',
    5: 'color:#389E0D;',
    7: 'color:#ff9933;',
    8: 'color:#ff0000;',
    10: 'color:#0066ff;'
  }

  export default {
    name: 'repairOrder',
    components: {
      Detail,
      DealConfirm,
      TransferOrder,
      PressOrder,
      RemarkOrder,
      BackOrder,
      ReturnVisit,
      CsmDetail,
      RejectReason,
      securityOrderInfo: () => import('../../safetySupervise/securityOrderManage/components/securityOrderInfo.vue')
    },
    data() {
      return {
        actionColWidth: 80,
        treeData: [],
        repairStatusMap: [],
        visitStatusMap: [],
        callCheckMap: [],
        ownersList: [],
        calcTypeList: [],
        paymenFilList: [],
        csmType: 'contactPhone',
        csmText: '',
        dateType: 'createTime',
        date: [moment().startOf('day'), moment().endOf('day')],
        query: {
          orgSNNo: '', // 所属机构orgSNNo
          userId: '',
          rstatus: '',
          callResult: '',
          callCheck: '',
          fromPlat: '',
          repairContent: ''
        },
        repairContentMap: [],
        fromPlatMap: [
          {
            value: 1,
            label: '呼叫中心'
          },
          {
            value: 7,
            label: '话务下单'
          },
          {
            value: 2,
            label: '微信'
          },
          {
            value: 6,
            label: '支付宝小程序'
          },
          {
            value: 8,
            label: 'APP'
          },
          {
            value: 9,
            label: '微信小程序'
          }
        ],
        roleTypeList: [],
        searchParams: {},
        tableData: {
          total: 0,
          data: []
        }
      }
    },
    computed: {
      ...mapGetters(['orgList', 'userInfo', 'corpSettingData', 'exportDomain']),
      column: function() {
        return [
          {
            type: 'index'
          },
          {
            prop: 'repairCode',
            label: '报修单号',
            width: 150,
            render: (h, { row }) => (
            <el-link underline={false} onClick={() => this.openDetail(row)}>
              {row.repairCode}
            </el-link>
          )
          },
          {
            prop: 'orgName',
            label: '责任机构',
            width: 110
          },
          {
            prop: 'userName',
            label: '处理人'
          },
          {
            prop: 'csmCode',
            label: '客户编号',
            width: 110,
            render: (h, { row }) => (
              <el-link underline={false} onClick={() => this.openCsmDetail(row)}>
                {row.csmCode}
              </el-link>
            )
          },
          {
            prop: 'csmName',
            label: '客户名称',
            width: 160
          },
          {
            prop: 'csmOrgName',
            label: '所属机构',
            width: 110
          },
          {
            prop: 'contact',
            label: '联系人'
          },
          {
            prop: 'contactPhone',
            label: '联系电话',
            width: 110
          },
          {
            prop: 'contactAddress',
            label: '联系地址',
            width: 200
          },
          {
            prop: 'rstatus',
            label: '状态',
            width: 110,
            render: (h, { row }) => (
            <span style={colorObj[row.rstatus]}>
              {row.rstatus
                ? formatColumnMap(this.repairStatusMap, 'value', row.rstatus, 'desc')
                : '未支付'}
            </span>
          )
          },
          {
            prop: 'checkId',
            label: '安检单号',
            width: 110,
            render: (h, { row }) => (
              <el-link v-show={row.checkId} underline={false} onClick={() => this.openCheckDetail(row)}>
                {row.checkId}
              </el-link>
            )
          },
          {
            prop: 'answer',
            label: '登记人'
          },
          {
            prop: 'createTime',
            label: '登记时间',
            width: 160,
            render: (h, { row }) => (
            <span>
              {row.createTime && parseTime(row.createTime, '{y}-{m}-{d} {h}:{i}')}
            </span>
          )
          },
          // {
          //   prop: 'createTime',
          //   label: '预约开始时间',
          //   width: 160,
          //   render: (h, { row }) => (
          //   <span>
          //     {row.createTime && parseTime(row.createTime, '{y}-{m}-{d} {h}:{i}')}
          //   </span>
          // )
          // },
          // {
          //   prop: 'dueTime',
          //   label: '预约结束时间',
          //   width: 160,
          //   render: (h, { row }) => (
          //   <span>{row.dueTime && parseTime(row.dueTime, '{y}-{m}-{d} {h}:{i}')}</span>
          // )
          // },
          {
            prop: 'repairContent',
            width: 200,
            label: '客户报修内容'
          },
          {
            prop: 'remark',
            label: '备注',
            width: 200
          },
          {
            prop: 'marker1',
            label: '维修员问题反馈',
            width: 200
          },
          {
            prop: 'marker2',
            label: '处理结果',
            width: 150
          },
          {
            prop: 'signDt',
            label: '完成时间',
            width: 140,
            render: (h, { row }) => (
            <span>{row.signDt && parseTime(row.signDt, '{y}-{m}-{d} {h}:{i}:{s}')}</span>
          ) },
          {
            prop: 'callUserName',
            label: '回访人'
          },
          {
            prop: 'callTime',
            label: '回访时间',
            width: 140,
            render: (h, { row }) => (
            <span>{row.callTime && parseTime(row.callTime, '{y}-{m}-{d}')}</span>
          )
          },
          {
            prop: 'callResult',
            label: '回访结果',
            width: 110,
            render: (h, { row }) => (
            <span>
              {row.callResult
                ? formatColumnMap(this.visitStatusMap, 'value', row.callResult, 'desc')
                : ''}
            </span>
          )
          },
          // {
          //   prop: 'callCheck',
          //   label: '回访调查',
          //   width: 110
          // },
          {
            prop: 'marker3',
            label: '回访处理说明',
            width: 110
          },
          {
            prop: 'marker4',
            label: '退单原因',
            width: 110
          },
          {
            prop: 'fromPlatName',
            label: '单据来源',
            width: 110
          },
          {
            prop: 'appointmentStartTime',
            label: '预约时间',
            width: 180,
            render: (h, { row }) => (
            <span>{row.appointmentStartTime && row.appointmentEndTime && ((parseTime(row.appointmentStartTime, '{y}-{m}-{d} {h}:{i}')) + (parseTime(row.appointmentEndTime, '~{h}:{i}')))}</span>
          ) },
          {
            prop: 'auditTime',
            label: '审核时间',
            width: 160,
            render: (h, { row }) => (
            <span>{row.auditTime && parseTime(row.auditTime, '{y}-{m}-{d} {h}:{i}:{s}')}</span>
          ) },
          {
            prop: 'transferTime',
            label: '派单时间',
            width: 160,
            render: (h, { row }) => (
            <span>{row.transferTime && parseTime(row.transferTime, '{y}-{m}-{d} {h}:{i}:{s}')}</span>
          ) },
          {
            prop: 'operateDt',
            label: '报修处理时间',
            width: 160,
            render: (h, { row }) => (
            <span>{row.operateDt && parseTime(row.operateDt, '{y}-{m}-{d} {h}:{i}:{s}')}</span>
          ) },
          {
            prop: 'dismissedTime',
            label: '驳回时间',
            width: 160,
            render: (h, { row }) => (
            <span>{row.dismissedTime && parseTime(row.dismissedTime, '{y}-{m}-{d} {h}:{i}:{s}')}</span>
          ) },
          {
            prop: 'dismissedReason',
            label: '驳回原因',
            width: 140
          },
          {
            label: '操作',
            align: 'center',
            fixed: 'right',
            render: (h, { row, $index }) => {
              return (
                <div>
                  <el-dropdown>
                    <span class='el-dropdown-link'>
                      更多<i class='el-icon-arrow-down el-icon--right'></i>
                    </span>
                    <el-dropdown-menu slot='dropdown'>
                        {row.rstatus === 1 &&
                          (
                         <el-dropdown-item>
                          <el-link
                            v-permission='3'
                            underline={false}
                            size='mini'
                            onClick={() => this.audit(row, $index)}
                          >
                            审核
                          </el-link>
                          </el-dropdown-item>
                          )
                        }
                      {row.rstatus === 2 && (
                        <el-dropdown-item>
                          <el-link
                            v-permission='4'
                            underline={false}
                            size='mini'
                            onClick={() => this.openPressOrder(row, $index)}
                          >
                            催单
                          </el-link>
                          </el-dropdown-item>
                        )}

                        {(row.rstatus === 2 || row.rstatus === 6) && (
                          <el-dropdown-item>
                            <el-link
                              v-permission='5'
                              underline={false}
                              size='mini'
                              onClick={() => this.openTransferOrder(row, $index)}
                            >
                              转派
                            </el-link>
                          </el-dropdown-item>
                        )}
                        {row.rstatus === 3 && (
                          <el-dropdown-item>
                            <el-link
                              v-permission='6'
                              underline={false}
                              size='mini'
                              onClick={() => this.dealConfirm(row, $index)}
                            >
                              处理确认
                            </el-link>
                          </el-dropdown-item>
                        )}
                        {(row.rstatus === 3 &&
                         <el-dropdown-item>
                            <el-link
                              underline={false}
                               v-permission='7'
                              size='mini'
                              onClick={() => this.dealReject(row, $index)}
                            >
                              驳回
                            </el-link>
                          </el-dropdown-item>
                        )}
                        {row.rstatus === 10 && (
                          <el-dropdown-item>
                            <el-link
                              v-permission='8'
                              underline={false}
                              size='mini'
                              onClick={() => this.openReturnVisit(row, $index)}
                            >
                              回访
                            </el-link>
                          </el-dropdown-item>
                        )}
                        {(row.rstatus === 1 || row.rstatus === 2 || row.rstatus === 6) && (
                          <el-dropdown-item>
                            <el-link
                              v-permission='9'
                              underline={false}
                              size='mini'
                              type='danger'
                              onClick={() => this.openBackOrder(row, $index)}
                            >
                              退单/确认
                            </el-link>
                          </el-dropdown-item>
                        )}
                        <el-dropdown-item>
                          <el-link
                            v-permission='10'
                            underline={false}
                            size='mini'
                            onClick={() => this.openRemark(row, $index)}
                          >
                            备注
                          </el-link>
                        </el-dropdown-item>
                        <el-dropdown-item>
                          <el-link
                            v-permission='11'
                            underline={false}
                            size='mini'
                            onClick={() => this.tryPrint(row, $index)}
                          >
                            打印
                          </el-link>
                        </el-dropdown-item>
                    </el-dropdown-menu>
                  </el-dropdown>
                </div>
              )
            }
          }
        ]
      }
    },
    watch: {
      $route: {
        handler: function(val, oldVal) {
          this.checkStatusByHash()
        },
        // 深度观察监听
        deep: true
      }
    },
    async created() {
      await Promise.all([this.getTreeData(), this.getOwnersList(), this.getMap()])
      this.checkStatusByHash()
      this.getRepairCommonkeys()
    },
    mounted() {
      this.getRepairCount()
      this.interval = setInterval(() => {
        this.getRepairCount()
      }, 60000)
    },
    beforeDestroy() {
      clearInterval(this.interval)
    },
    methods: {
      // 获取所属机构数据
      async getTreeData() {
        const data = this.orgList.map((item) => ({
          label: item.name,
          ...item
        }))
        this.treeData = getTreeData(data)
      },
      // 选择所属机构
      selectTreeChange(value) {
        this.getOwnersList(value.orgId)
        this.query.userId = ''
      },
      closeTree(v) {
        this.$set(this.query, 'userId', '')
        this.getOwnersList()
      },
      // 根据路由参数设置状态
      checkStatusByHash() {
        const params = this.$route.query
        if (params) {
          if (params.type === '1') {
            this.query.rstatus = 6
          }
          if (params.type === '2') {
            this.query.rstatus = 2
          }
          this.query.rstatus = params.rstatus ? Number(params.rstatus) : ''
        }
        this.$refs.lbTable.fetch({ currentPage: 1 })
      },
      _getQuery(obj) {
        const query = {}
        for (const key in obj) {
          if (obj.hasOwnProperty(key)) {
            if (obj[key] !== '') {
              query[key] = obj[key]
            }
          }
        }
        return query
      },
      async fetchData({ currentPage, pageSize }) {
        const query = {
          ...this._getQuery(this.query),
          currentPage,
          pageSize
        }
        if (this.date && this.date.length > 0) {
          query[this.dateType] = this.date[0]
          query[`${this.dateType}End`] = this.date[1]
          const diff = moment(this.date[1]).diff(moment(this.date[0]), 'days')
          if (diff > 366) {
            this.$message.error('日期跨度不能超过一年')
            return
          }
        }
        query[this.csmType] = this.csmText
        const res = await queryRepairList(query)
        this.searchParams = query
        this.tableData.data = res.data.rows
        if (currentPage === 1) this.tableData.total = res.data.total
        this.flexColumnWidth()
      },
      async getRepairCommonkeys() {
        const params = {
          keyFun: 2,
          keyAttr: 1
        }
        const res = await repairCommonkeys(params)
        if (res && res.data) {
          this.repairContentMap = res.data
        }
      },
      async getRepairCount() {
        const query = {
          callCheck: null,
          rstatus: 2,
          createTime: parseTime(new Date(), '{y}-{m}-{d}'),
          currentPage: 1,
          pageSize: 1
        }
        const res = await queryRepairList(query)
        if (res.data.total > 0) {
          const dom = document.getElementById('newRepair')
          dom.play()
        }
      },
      // 查询处理人列表
      async getOwnersList(orgId) {
        const res = await queryOwnerList({
          orgId: orgId || -1
        })
        this.ownersList = res.data
      },
      // 查询所有枚举
      async getMap() {
        const res = await queryRepairOrderMap()
        this.repairStatusMap = JSON.parse(res.data.repairStatus) // 报修单状态
        this.visitStatusMap = JSON.parse(res.data.visitStatusMap) // 回访结果
        this.callCheckMap = JSON.parse(res.data.backVisitInfos) // 回访调查
        const [res1, res2] = await Promise.all([
          mergeAsyncFunc(queryMap, { enumName: 'PaymentMethod' }),
          mergeAsyncFunc(queryMap, { enumName: 'CalcType' })
        ])
        this.paymenFilList = res1.data.filter(item => item.value === 1 || item.value === 2 || item.value === 16 || item.value === 128 || item.value === 256 || item.value === 2048) // 支付方式
        this.calcTypeList = res2.data // 收款方式
      },
      async openDetail(row) {
        await this.$refs.detail.open(row)
      },
      // 点击客户名称
      async openCsmDetail(row) {
        await this.$refs.csmDetail.open(row)
      },
      // 点击安检单号
      async openCheckDetail(row) {
        await this.$refs.securityOrderInfo.open({ checkId: row.checkId }, '安检信息')
      },
      // 点击催单
      async openPressOrder(row) {
        const res = await this.$refs.pressOrder.open({
          billCode: row.repairCode,
          billType: 3,
          text: '处理'
        })
        if (res) {
          if (this.$refs.detail.visible) this.$refs.detail.getDetail(row)
        }
        this.$refs.lbTable.fetch({ currentPage: 1 })
      },
      // 点击处理确认
      async dealConfirm(row) {
        await this.$refs.dealConfirm.open(row)
        this.$refs.lbTable.fetch({ currentPage: 1 })
      },
      // 点击回访
      async openReturnVisit(row) {
        await this.$refs.returnVisit.open(row)
        this.$refs.lbTable.fetch({ currentPage: 1 })
      },
      // 点击退单
      async openBackOrder(row) {
        await this.$refs.backOrder.open(row)
        this.$refs.lbTable.fetch({ currentPage: 1 })
      },
      // 点击转派
      async openTransferOrder(row) {
        await this.$refs.transferOrder.open(row)
        this.$refs.lbTable.fetch({ currentPage: 1 })
      },
      // 点击备注
      async openRemark(row) {
        await this.$refs.remarkOrder.open(row)
        this.$refs.lbTable.fetch({ currentPage: 1 })
      },
      exportFile() {
        const _this = this
        this.$confirm(`确定导出数据？`, '提示', {
          type: 'warning'
        }).then(() => {
          const copyColumn = JSON.parse(JSON.stringify(this.column))
          copyColumn.pop()
          const str = {}
          copyColumn.forEach((item) => {
            str[item.prop] = item.label
          })
          queryExportRepairOrderList({
            paramInfo: _this._getQuery(_this.searchParams),
            kv: str // 表格列
          }).then((res) => {
            window.open(`${this.exportDomain}/page/export/frame?key=${res.data}`, '_blank')
          })
        })
      },
      async tryPrint(row) {
        const params = {
          repairCode: row.repairCode
        }
        const { status, data } = await queryRepairOrderDetail(params)
        if (status === 200) {
          this.print(row, data)
        }
      },
      print(row, resData) {
        const cache = JSON.parse(localStorage.tp)
        if (!cache) {
          this.$message.warning('请先设置打印模板')
          return
        }
        const temp = cache['18']
        if (!temp) {
          this.$message.warning('请先设置打印模板')
          return
        }

        row.createTime = moment(row.transactTime).format('YYYY-MM-DD hh:mm')
        const rc = row.repairContent
        if (rc) {
          if (rc.lastIndexOf('。') !== -1 && rc.split('。').length > 1) {
            row.repairItem = rc.split('。')[0]
            row.repairDesc = rc.split('。')[1]
          } else {
            row.repairItem = rc
          }
          // 换行
          if (row.repairItem.length > 38) {
            row.repairItem2 = row.repairItem.substring(39)
            row.repairItem = row.repairItem.substring(0, 39)
          }
          if (row.repairDesc && row.repairDesc.length > 38) {
            row.repairDesc2 = row.repairDesc.substring(39)
            row.repairDesc = row.repairDesc.substring(0, 39)
          }
        }
        let printcmd = {
          cmd: 2,
          title: `正在对退修单${row.repairCode}进行退修单打印`,
          elements: []
        }
        printcmd = { ...printcmd, ...temp }
        if (!window.jCPrint || !window.jCPrint.ws) {
          this.$message.error('打印未连接')
          return
        }
        window.jCPrint.process(printcmd, temp, row, resData)
        if (window.jCPrint.firePush(JSON.stringify(printcmd))) {
          this.$message.success('打印指令已发送')
        } else {
          this.$message.error('打印未连接')
        }
      },
      search() {
        this.$refs.lbTable.fetch({ currentPage: 1 })
      },
      // 自适应表格列宽
      flexColumnWidth() {
        this.$nextTick(() => {
          let max = 0
          const actionColDom = document.getElementsByClassName('action-col')
          for (let i = 0; i < actionColDom.length; i++) {
            if (actionColDom[i].tagName === 'TD' || actionColDom[i].tagName === 'TH') {
              let width = 20
              const linkDom = actionColDom[i].childNodes[0].childNodes[0].childNodes
              linkDom.forEach((it) => {
                width += it.offsetWidth + 10
              })
              if (width > max) max = width
            }
          }
          this.actionColWidth = max > 60 ? max - 10 : 50
        })
      },
      reset() {
        this.$refs.form.resetFields()
      },
      async audit(row) {
        const params = {
          repairCode: row.repairCode
        }
        const res = await repairAudit(params)
        if (res && res.data) this.$message.success('操作成功')
        this.search()
      },
      async dealReject(row) {
        await this.$refs.rejectReason.open(row)
        this.search()
      }
    }
  }
</script>

<style lang="scss" scoped>
.el-form-item .el-form-item {
  margin-bottom: 0;
}
.merge-item {
  /deep/ .el-form-item__content {
    display: flex;
  }
}
.btn-group {
  display: flex;
  justify-content: space-between;
}
</style>
